<template>
  <!-- 签约管理 * 待签约列表 -->
  <div>
    <div class="refuter">
      <!-- 第一行 - 签约  -->
      <div
        style="
          border-bottom: 1px dashed #efefef;
          display: flex;
          margin-bottom: 30px;
        "
        class="refuter_top"
      >
        <div class="display" style="margin-left: 20px">
          <b class="lhy_b">机构编号:</b>
          <el-input
            v-model="input1"
            class="w-50 m-2"
            size="large"
            style="width: 300px; margin-left: 20px"
            placeholder="请输入机构编号"
          />
        </div>
        <div class="display" style="margin-left: 30px">
          <b class="lhy_b">机构名称:</b>
          <el-input
            v-model="input1"
            class="w-50 m-2"
            size="large"
            style="width: 300px; margin-left: 20px"
            placeholder="请输入机构名称"
          />
        </div>
        <div style="margin-left: 17%">
          <el-button>新增机构</el-button>
          <el-button style="margin-left: 20px">查询</el-button>
          <el-button style="margin-left: 20px" @click="onBatchExport"
            >导出</el-button
          >
        </div>
      </div>
      <!-- table表格 -->
      <el-table
        :data="ebooks1.books.slice((pages - 1) * pageSize, pages * pageSize)"
        style="width: 100%"
      >
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column type="index" label="编号" width="55">
        </el-table-column>
        <el-table-column property="name" label="机构名称" width="220" />
        <el-table-column property="userName" label="负责人姓名" />
        <el-table-column property="mobile" label="负责人电话" />
        <el-table-column property="address" label="机构地址" width="220" />
        <el-table-column property="img" label="机构图片">
          <template #default="scope">
            <el-image
              style="width: 75px; height: 75px"
              :src="scope.row.img"
              :fit="fit"
            />
          </template>
        </el-table-column>

        <el-table-column property="state" label="签约状态">
          <template #default="scope">
            <el-tag v-if="scope.row.state" type="success">已签约</el-tag>
            <el-tag v-else type="danger">未签约</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <a style="margin-right: 10px">编辑</a>
          <a>删除</a>
        </el-table-column>
      </el-table>
      <div style="margin-top: 15px">
        <el-pagination
          @update:current-page="changePage"
          v-model:current-page="page"
          background
          :page-size="pageSize"
          layout="prev, pager, next"
          :total="ebooks1.books.length"
        />
      </div>
    </div>
  </div>
</template>
  
  <script setup>
import { ref, onMounted, reactive } from "vue";
import { ElTable } from "element-plus";
import axios from "axios";
import request from "@/request";
// 导出带图片的表
import table2excel from "js-table2excel";

let ebooks1 = reactive({
  books: [],
});
let getDate = () => {
  axios.get("http://localhost:3461/api/organ").then((res) => {
    // console.log(res.data.data);
    ebooks1.books = res.data.data;
    console.log(ebooks1.books, "156");
  });
};
onMounted(() => {
  getDate();
});

// 当前页
let pages = ref(1);
// 每页显示条数
let pageSize = 5;
// 更改页数
let changePage = (page) => {
  console.log(page);
  pages.value = page;
  console.log(pages);
};

/* 导出开始 */
// 导出
// const list_data = reactive({
//   books:[]
// })
const onBatchExport = () => {
  //导出按钮
  console.log(123);
  console.log(ebooks1.books);
  const column = [
    //数据表单
    {
      title: "编号", //表头名称title
      key: "_id", //数据
      type: "text", //类型
    },
    {
      title: "机构名称",
      key: "name",
      type: "text",
    },
    {
      title: "负责人姓名",
      key: "userName",
      type: "text",
    },
    {
      title: "负责人电话",
      key: "mobile",
      type: "text",
    },
    {
      title: "机构地址",
      key: "address",
      type: "text",
    },
    {
      title: "机构图片",
      key: "img",
      type: "image",
      width: 80,
      height: 80,
    },
    {
      title: "签约状态",
      key: "state",
      type: "text",
    },
  ];

  let tableDatas = JSON.parse(JSON.stringify(ebooks1.books)); //将数据转化为字符串(list_data数据是接口数据，把名称换成自己的数据即可)
  let datas = tableDatas;
  table2excel(column, datas, "数据"); //表单数据名称
};
</script>
  
  <style lang="scss" scoped>
</style>